package struts.action;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import struts.form.ActionForm;
import struts.form.LoginForm;
import struts.service.UserService;
import struts.service.impl.UserServiceImpl;
import struts.service.vo.UserVo;

public class LoginAction implements Action {

	public String execute(HttpServletRequest request,
			HttpServletResponse response, ActionForm form,
			Map<String, String> actionForward) {
		UserService userService = new UserServiceImpl();
		UserVo user = userService.getVO(request.getParameter("username"));
		String url = "shibai";
		LoginForm login = (LoginForm) form;
		if(login.getUsername().equals("admin")){
			url = "chenggong";
		}
		if(null!=user){
			request.setAttribute("user", user);
		}
		return actionForward.get(url);
	}

}
